package com.zx.Controller;

import com.github.pagehelper.PageInfo;
import com.zx.entity.Page;
import com.zx.entity.User;
import com.zx.service.UserService;
import com.zx.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user")
public class UserController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pageNum = req.getParameter("pageNum");
        String pageSize = req.getParameter("pageSize");

        Page page = new Page();
        if (pageNum != null) {
            page.setPageNum(Integer.parseInt(pageNum));
        }
        if (pageSize != null) {
            page.setPageSize(Integer.parseInt(pageSize));
        }

        UserService userService = new UserServiceImpl();
        PageInfo<User> pi = userService.queryUsers(page);
        req.setAttribute("pageData", pi);
        req.getRequestDispatcher("/user.jsp").forward(req,resp);
    }
}
